package com.iwayin.web.action.answer;

import java.util.List;

import com.iwayin.core.bo.answer.AnswerBO;
import com.iwayin.core.dataobject.AnswerDO;
import com.iwayin.core.utils.exception.BOException;
import com.iwayin.core.vo.AnswerVO;
import com.iwayin.web.action.BaseAction;
import com.iwayin.web.common.AjaxResult;

public class AnswerAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1707573700414180697L;
	private AnswerDO query;
	private AjaxResult ajaxResult;
	private AnswerBO answerBO;
	private List<AnswerDO> answers;
	private List<AnswerVO> answerVOs;

	/**
	 * @description 添加answer
	 * @author ZhangLei
	 * @return
	 */
	public String addAnswer() {
		try {
			query.setUserId(this.getLoginUser().getId());
			this.answerBO.addAnswer(query);
			ajaxResult = AjaxResult.succResult();
		} catch (BOException e) {
			ajaxResult = AjaxResult.errorResult(e.getMessage());
		} catch (Exception e) {
			ajaxResult = AjaxResult.errorResult("系统异常");
		}
		return SUCCESS;
	}

	/**
	 * @description 添加answer
	 * @author ZhangLei
	 * @return
	 */
	public String findAnswers() {
		answers = this.answerBO.findAnswers(query);
		return SUCCESS;
	}

	public String getVoteRate() {
//		try {
			answers = this.answerBO.findAnswers(query, this.getLoginUser().getId());
//			ajaxResult = AjaxResult.succResultAndInitMap();
//			ajaxResult.getResultMap().put("answers", answers);
//		}catch (Exception e) {
//			ajaxResult = AjaxResult.errorResult("系统异常");
//		}
		return SUCCESS;
	}
	public String findAskReceivedAnswers(){
		answerVOs=this.answerBO.findAskReceivedAnswers(query,this.getLoginUser().getId());
		return SUCCESS;
	}
	public AnswerDO getQuery() {
		return query;
	}

	public void setQuery(AnswerDO query) {
		this.query = query;
	}

	public AjaxResult getAjaxResult() {
		return ajaxResult;
	}

	public void setAjaxResult(AjaxResult ajaxResult) {
		this.ajaxResult = ajaxResult;
	}

	public void setAnswerBO(AnswerBO answerBO) {
		this.answerBO = answerBO;
	}

	public List<AnswerDO> getAnswers() {
		return answers;
	}

	public void setAnswers(List<AnswerDO> answers) {
		this.answers = answers;
	}

	public List<AnswerVO> getAnswerVOs() {
		return answerVOs;
	}

	public void setAnswerVOs(List<AnswerVO> answerVOs) {
		this.answerVOs = answerVOs;
	}
	
}
